from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options

chromedriver_path = 'E:\pythonWorkSpace\py_study\k.自动化/chromedriver.exe'
service = Service(chromedriver_path)
options = Options()

# 防检测
# 这行代码的作用是隐藏浏览器正在被自动化工具控制的特征，避免一些网站检测到你使用的是自动化脚本。
# options.add_argument("--disable-blink-features=AutomationControlled")
options.add_experimental_option('excludeSwitches', ['enable-automation'])

# 无头 与设置UA
# options.add_argument('--headless') # 即浏览器在后台运行，不会显示界面
# options.add_argument('user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36')

# 设置移动端模式
# mobile_emulation = {
#     "deviceMetrics": {"width": 375, "height": 812, "pixelRatio": 3.0},
#     "userAgent": "Mozilla/5.0 (Linux; Android 10; Pixel 4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.105 Mobile Safari/537.36"
# }
# options.add_experimental_option("mobileEmulation", mobile_emulation)

# 禁止加载图片
# options.add_argument("--blink-settings=imagesEnabled=false")

# 禁用js
# options.add_argument("--disable-javascript")

print(options.arguments)

driver = webdriver.Chrome(service=service, options=options)

driver.maximize_window()


driver.get("https://www.cninfo.com.cn/")

print(driver.page_source)
input()
driver.quit()